<template>
  <div>
    <el-table
      :data="tableData"
      border
      style="width: 100%">
      <el-table-column
        fixed
        prop="Tno"
        label="教师号"
        width="150">
      </el-table-column>
      <el-table-column
        prop="Tname"
        label="教师名"
        width="120">
      </el-table-column>
      <el-table-column
        prop="Trank"
        label="教师等级"
        width="120">
      </el-table-column>
      <el-table-column
        prop="Tspeciality"
        label="特长"
        width="120">
      </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            @click="handleEdit(scope.row)">编辑</el-button>
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      background
      layout="prev, pager, next"
      page-size="6"
      :total="total"
      @current-change="page">
    </el-pagination>
  </div>
</template>

<script>
export default {
  methods: {
    handleDelete(row){
      const _this = this
      this.axios.post('http://localhost:8152/api/auth/teacher/delete',{Tno:row.Tno}).then( (res)=> {
        _this.$alert(row.Tname+'删除成功！', '消息', {
          confirmButtonText: '确定',
          callback: action => {
            window.location.reload()
          }
        })
      })
    },
    handleEdit(row) {
      this.$router.push({
        path:'/update2',
        query:{
          row
        }
      })
    },
    page(){
      const _this = this
      this.axios.post('http://localhost:8152/api/auth/teacher/findall').then(function (resp) {
        _this.tableData = resp.data
        _this.total = resp.data
      })
    }
  },
  created () {
    const _this = this;
    this.axios.post('http://localhost:8152/api/auth/teacher/findall').then((res) => {
      _this.tableData = res.data
      //_this.total = res.data.totalElements
    })
  },
  data() {
    return {
      total:null,
      tableData:null
    }
  }
}
</script>
